package org.ccay.excel.importer.validate;

/**
 * 状态标识	
 * @author chaowangbang
 * @since Mar 13, 2012
 */
public class Status implements IStatus {
	
	/** 状态码 **/
	private int state;
	
	/** 消息 **/
	private String message;
	
	/** 创建一个错误状态标识	
	 * @author chaowangbang
	 * @since Mar 14, 2012
	 * @return
	 */
	public static IStatus error() {
		return new Status(IStatus.ERROR);
	}
	
	/** 创建一个错误状态标识	
	 * @author chaowangbang
	 * @since Mar 14, 2012
	 * @param message
	 * @return
	 */
	public static IStatus error(String message) {
		return new Status(IStatus.ERROR, message);
	}
	
	/**
	 * 构造函数
	 * 
	 * @param status
	 */
	public Status(int status) {
		this.state = status;
	}
	
	/**
	 * @param status
	 * @param message
	 */
	public Status(int status, String message) {
		this.state = status;
		this.message = message;
	}

	/* (non-Javadoc)
	 * @see org.ccay.excel.importer.validate.IStatus#getErrorMessage()
	 */
	public String getMessage() {
		return this.message;
	}
	
	/** 
	 * 设置消息。
	 * 	
	 * @author chaowangbang
	 * @since Mar 14, 2012
	 * @param message
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	/* (non-Javadoc)
	 * @see org.ccay.excel.importer.validate.IStatus#getStatus()
	 */
	public int getStatus() {
		return this.state;
	}

	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + state;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		
		if (obj == null) {
			return false;
		}
		
		if (getClass() != obj.getClass()) {
			return false;
		}
		
		final Status other = (Status) obj;
		if (state != other.state) {
			return false;
		}
		
		return true;
	}

	/* (non-Javadoc)
	 * @see org.ccay.excel.importer.validate.IStatus#isOK()
	 */
	public boolean isOK() {
		return this.state==IStatus.OK;
	}
	
}
